<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action {
	public function index(){
		$this->token=md5(create_uuid(""));
		$this->display();
	}
	public function commonLogin(){		
		if(I('code','','strtolower') != session('verify')){
			outError('验证码错误');die;
		}
		$db = M('profile');
		$profile = $db->where(array('usename' => I('username')))->find();
		if(!$profile || $profile['password'] != I('password')){//I('password','','md5')
			outError('账号密码错误');die;
		}
		else
		{
			//将某些信息保存到session
			$_SESSION['profile_id']=$profile['id'];
			
			//生成认证条件
			$map =   array();
			// 支持使用绑定帐号登录
			$map['username']	=  I('username');
			//$map["status"]	=	array('gt',0);
			import ( '@.ORG.Util.RBAC' );
			$authInfo = RBAC::authenticate($map);
			if(false === $authInfo) {
				outError("???");
			}else {
				$_SESSION[C('USER_AUTH_KEY')]	=	$authInfo['id'];
				
				if($authInfo['username']=='admin') {
					$_SESSION[C('ADMIN_AUTH_KEY')]=	true;
				}
			}
			// 缓存访问权限
			RBAC::saveAccessList();
			$db = M('customer');
			$customer= $db->where(array('id' => $profile['cid']))->find();
			session('customer', $customer);
			outSuccess("OK");
		}
	}

	public function qrcode(){
		$data="万岁";
		$filename="xx.png";
		$errorCorrectionLevel = 'H'; // L-smallest, M, Q, H-best
		$matrixPointSize = 20; // 1-50
		$margin=0;
		import('Class.Qrcode',APP_PATH);
		QRcode::png($data, false, $errorCorrectionLevel, $matrixPointSize,$margin);
	}
	
	public function verify()
	{
		import('Class.Qrcode',APP_PATH);
		Image::verify();
	}
	
	function logout(){
	 if(isset($_SESSION[C('USER_AUTH_KEY')])) {
            unset($_SESSION[C('USER_AUTH_KEY')]);
            unset($_SESSION);
            session_destroy();
            $this->success('登出成功！',__URL__.'/index/');
        }else {
            $this->error('已经登出！');
        }
	}
}